package com.uzhie.jt808.msg.entity.JT_200;

import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.IPositionAdditionalItem;

import java.util.HashMap;
import java.util.Map;

/**
 * 1078 视频相关报警扩展
 * Created by lilongfei on 2018/7/31.
 */
public class Media_Warn implements IPositionAdditionalItem {

    @Override
    public final int getAdditionalId()
    {
        return 0x14;
    }
    @Override
    public final byte getAdditionalLength()
    {
        return 0x04;
    }

    /* 信号报警相关
    *1,视频信号丢失 2,视频信号遮挡 4,存储单元故障 8,其他视频设备故障 16,客车超员 32,异常驾驶行为  64,特殊报警对象达到存储阈值
    */
    private int type;


    private Map<Integer,Integer> status;

    public Map<Integer, Integer> getStatus() {
        return status;
    }

    public void setStatus(Map<Integer, Integer> status) {
        this.status = status;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public byte[] WriteToBytes() {
        return BitConverter.GetBytes(getType());
    }

    @Override
    public void ReadFromBytes(byte[] bytes) {
        setType(BitConverter.ToUInt32(bytes,0));
        status = new HashMap<>();
        for (int i=0  ;i<7;i ++){
            byte t = (byte) ((BitConverter.ToUInt32(bytes,0) >> (i)) & 0x0001);
            if (t == 1) status.put(i, (int) t);
//            System.out.println("当前通道号:" + i + ", 设备状态 : " + (t==0 ? "正常":"报警"));
        }
    }
}
